import React, { Component } from 'react'
import PubSub from 'pubsub-js'

import Item from '../Item'
//import PropTypes from 'prop-types'
import './index.css'
export default class List extends Component {
  state = {
    list:[],
    isFirst:true,
    isLoading:false,
    err:'',
  }
  componentDidMount(){
    //订阅
    this.token = PubSub.subscribe('getuserlist',(msg,data)=>{
      console.log('pubsub=>',msg,data)
      this.setState({...data})
    })
  }
  componentWillUnmount(){
    //销毁订阅
    PubSub.unsubscribe(this.token)
  }
  render() {
    const {list,isFirst,isLoading,err} = this.state
    console.log('list render==>',this.state)
    let msg = ''
    if(isFirst){
      msg = '请输入名字搜索.....'
    }
    if(isLoading){
      msg = '正在搜索ing.......'
    }
    if(err){
      msg = err
    }
    return (
        <div className="row">
            <h2>{msg}</h2>
            <Item list={list}/>
        </div>
    )
  }
}
